package com.things8.iot.common.result;

import com.things8.iot.common.enums.GlobalResultEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/9 21:33
 */
@Getter
@Setter
public class GlobalException extends RuntimeException {

    private String msg;
    private int code = 500;

    public GlobalException(String msg, int code) {
        this.msg = msg;
        this.code = code;
    }

    public GlobalException(String msg) {
        this.msg = msg;
    }

    public GlobalException(GlobalResultEnum resultEnum) {
        this.msg = resultEnum.getMsg();
        this.code = resultEnum.getCode();
    }

    public GlobalException(Throwable throwable, String msg) {
        super(throwable);
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "GlobalException{" +
                "msg='" + msg + '\'' +
                ", code=" + code +
                '}';
    }
}
